/**
 * 
 * @author Robert Wilson
 * @version $1.0$
 * @23 May 2011
 */
package engine;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.awt.Color;

import model.Snake;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import common.Direction;

/**
 * @author r.wilson
 *
 */
public class SnakeTest {

	private Snake snake1;
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		snake1 = new Snake(Direction.NORTH, Color.BLACK);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		snake1 = null;
	}

	/**
	 * Test method for {@link model.Snake#eaten()}.
	 */
	@Test
	public void testEaten() {
		
		//ensure the snake is 1 long
		assertTrue("should be 1 long, but was " + snake1.getLocations().length, 
				snake1.getLocations().length == 1);
		
		//make the snake eat then check that it's length increased.
		snake1.eaten();
		assertTrue("should be 2 long, but was " + snake1.getLocations().length, 
				snake1.getLocations().length == 2);
		
		//make the snake eat then check that it's length increased.
		snake1.eaten();
		assertTrue("should be 3 long", snake1.getLocations().length == 3);
	}

	/**
	 * Test method for {@link model.Snake#changeDirection(common.Direction)}.
	 */
	@Test
	public void testChangeDirection() {
		assertTrue("Current direction is NORTH", snake1.getDirection().equals(Direction.NORTH));
		snake1.changeDirection(Direction.SOUTH);
		assertTrue("Current direction should be SOUTH", snake1.getDirection().equals(Direction.SOUTH));
		snake1.changeDirection(Direction.EAST);
		assertTrue("Current direction should be EAST", snake1.getDirection().equals(Direction.EAST));
		snake1.changeDirection(Direction.WEST);
		assertTrue("Current direction should be WEST", snake1.getDirection().equals(Direction.WEST));
		snake1.changeDirection(Direction.NORTH);
		assertTrue("Current direction should be NORTH", snake1.getDirection().equals(Direction.NORTH));
	}

	/**
	 * Test method for {@link model.Snake#getLocations()}.
	 */
	@Test
	public void testGetLocations() {
		snake1.eaten();
		snake1.eaten();
		snake1.eaten();
		assertTrue("snake should have been 4 long", snake1.getLocations().length == 4);
	}

}
